/*
   Copyright 2009 Abdulla Abdurakhmanov (abdulla@latestbit.com)
   Original sources are available at www.latestbit.com

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/


package org.latestbit.smartobjects.examples.chat.server;

import org.latestbit.smartobjects.examples.chat.*;
import org.latestbit.smartobjects.*;
import org.latestbit.smartobjects.network.IEndpointLocation;
import org.lineargs.LineArgsParser;

public class Main {
	
	public void publishService(CommandLineOptions options) throws Exception {
		ISmartBus bus = new SmartBus();
		System.out.println("Starting service...");
		ChatServiceSyncSkeleton skeleton = new ChatServiceSyncSkeleton ( new ChatServiceImpl(options) );
		IEndpointLocation location = bus.createEndpointLocation("tcp://0.0.0.0:"+options.getPort());
		System.out.println("Publishing service on "+location);
		skeleton.publish(bus, location);
		System.out.println("Started! Please enter to stop");
		System.in.read();
		skeleton.destroy();
		bus.destroy();
	}

	public static void main(String[] args) throws Exception {
		LineArgsParser laParser = new LineArgsParser();
		CommandLineOptions options = laParser.parse(CommandLineOptions.class, args);
		new Main().publishService(options);
		
	}

}
